<?php
namespace Admin\Controller;
use Think\Controller;
/**
* 红包相关管理
*/
class RedController extends Controller{
	//平台红包列表
	public function platRed(){
		$page_no = I('get.p') ? I('get.p') : 1;
        $page_size = $_GET['page_size'] ? $_GET['page_size'] : 10;
        if($_GET['user_name']){
			$where['b.username'] = $_GET['user_name'];
		}
		$data = M('platform_redlog a')
				->page($page_no, $page_size)
				->field('a.id,a.user_id,a.money,a.add_time,a.activity_id,a.content,b.username,c.title')
				->join('left join zm_user b on a.user_id=b.id')
				->join('left join zm_activity c on a.activity_id=c.id')
				->where($where)->select();
		$count = M("platform_redlog a")->join('left join zm_user b on a.user_id=b.id')->where($where)->count();
		$Page = new \AntAge\Page($count, $page_size);
        $show = $Page->show();
        $this->assign('page', $show);
        $this->assign("count", $count);
		$this->assign('data',$data);
		$this->display();
	}
	//用户红包列表
	public function userRed(){
		$page_no = I('get.p') ? I('get.p') : 1;
        $page_size = $_GET['page_size'] ? $_GET['page_size'] : 10;
		$user_id = $_GET['user_id'];
		if($user_id){
			$where['a.user_id'] = $user_id;
		}
		if($_GET['user_name']){
			$where['b.username'] = $_GET['user_name'];
		}
		$data = M('red_money a')
				->field('a.id,a.user_id,a.money,a.type,a.status,a.get_time,a.content,a.add_time,a.activity_id,a.content,b.username,c.title')
				->page($page_no, $page_size)
				->join('left join zm_user b on a.user_id=b.id')
				->join('left join zm_activity c on a.activity_id=c.id')
				->where($where)->select();
		$count = M("red_money a")->join('left join zm_user b on a.user_id=b.id')->where($where)->count();
		$Page = new \AntAge\Page($count, $page_size);
        $show = $Page->show();
        $this->assign('page', $show);
        $this->assign("count", $count);
		$this->assign('data',$data);
		$this->display();
	}

	public function explain(){
		$data = M('explain')->where('id=1')->find();
		$this->assign('data',$data);
		$this->display();
	}

	public function updateExplain(){
		$res = M('explain')->where('id=1')->save($_POST);
		if($res === false){
			$this->ajaxReturn(array('status'=>0,'message'=>'失败'));
		}
		$this->ajaxReturn(array('status'=>1,'message'=>'成功'));

	}
}